	$(function() {
			$( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
			$( "#datepicker1" ).datepicker({ dateFormat: 'yy-mm-dd' });
			$( "#datepicker2" ).datepicker({ dateFormat: 'yy-mm-dd' });
			$( "#datepicker3" ).datepicker({ dateFormat: 'yy-mm-dd' });
			$( "#datepicker4" ).datepicker({ dateFormat: 'yy-mm-dd' });
			$( "#datepicker5" ).datepicker({ dateFormat: 'yy-mm-dd' });
			$( "#datepicker6" ).datepicker({ dateFormat: 'yy-mm-dd' });
			$( "#datepicker7" ).datepicker({ dateFormat: 'yy-mm-dd' });
			$( "#datepicker8" ).datepicker({ dateFormat: 'yy-mm-dd' });
		});

	function numberFormat(nStr){
		    nStr += '';
		    x = nStr.split('.');
		    x1 = x[0];
		    x2 = x.length > 1 ? '.' + x[1] : '';
		    var rgx = /(\d+)(\d{3})/;
		    while (rgx.test(x1))
		    	x1 = x1.replace(rgx, '$1' + ',' + '$2');
		    return x1 + x2;
	}

     var chart;
     var f;
     f = $("#nhan_biet").val();
   //  alert(f);
     $(document).ready(function() {
    // an hien cac form
    	       $("#form_an1").hide();
    	       $("#form_an2").hide();
    	       $("#form_an3").hide();
    	       $(".label_product").hide();
	   		   $(".product_game").hide();
	   		   $(".product_theme").hide();
	   	       $(".product_app").hide();
	   		   $(".product_temp").hide();
    	       $("#dong_2").hide(); $("#dong_3").hide();
    	       $("#dong_4").hide(); $("#dong_5").hide();
    	       $("#dong_6").hide(); $("#dong_7").hide();
    	       $("#dong_8").hide(); $("#dong_9").hide();
    	       $("#dong_10").hide(); $("#dong_11").hide();
    	       var test_site = $("#test_site").val();
    	       var date_time = $("#date_time").val();
               var select_chart = $("#model_chart").val();
               if(select_chart == 1){
                  	$("#form_container").show();
                  	$("#form_an2").hide();
                  	$("#form_an3").hide();
                  	$("#form_an1").show();
               }
               if(select_chart == 2){
                  	$("#form_an1").hide();
                  	$("#form_an3").hide();
                    $("#form_an2").show();
               }
               if(select_chart == 3){
                 	$("#form_an1").hide();
                 	$("#form_an2").hide();
                   $("#form_an3").show();
              }
               var select_time = $("#time").val();
               if(select_time == 1){
            	   $("#dong_2").hide();
        	       $("#dong_3").hide();
               }
               if(select_time == 2){
            	   $("#dong_2").show();
              	   $("#dong_3").show();
               }

               var select_time1 = $("#time1").val();
               if(select_time1 == 1){
            	   $("#dong_4").show();
        	       $("#dong_5").hide();
        	       $("#dong_6").hide();
        	       $("#dong_7").hide();
               }
               if(select_time1 == 2){
            	   $("#dong_4").hide();
        	       $("#dong_5").show();
        	       $("#dong_6").hide();
        	       $("#dong_7").hide();
               }
               if(select_time1 == 3){
            	   $("#dong_4").hide();
        	       $("#dong_5").hide();
        	       $("#dong_6").show();
        	       $("#dong_7").show();
               }
               
               var select_time2 = $("#time_chanel").val();
               if(select_time2 == 1)
	           	{
	           		$("#dong_8").show();
	           	       $("#dong_9").hide();
	           	       $("#dong_10").hide();
	           	       $("#dong_11").hide();
	           	}
	           	if(select_time2 ==2 )
	           	{
	           		$("#dong_8").hide();
	           	       $("#dong_9").show();
	           	       $("#dong_10").hide();
	           	       $("#dong_11").hide();
	           	}
	           	if(select_time2 == 3)
	               {
	           		   $("#dong_8").hide();
	           	       $("#dong_9").hide();
	           	       $("#dong_10").show();
	           	       $("#dong_11").show();
	               }

               var product = $("#type_product").val();
               if(product == 1){
           		$(".label_product").show();
           		$(".product_game").show();
           		$(".product_theme").hide();
           		$(".product_app").hide();
           		$(".product_temp").hide();
           		if(select_chart == 1) $("#form_an2").hide();
        		else $("#form_an1").hide();
                }
           	
	           	if(product == 2){
	           		$(".label_product").show();
	           		$(".product_game").hide();
	           		$(".product_theme").hide();
	           		$(".product_app").show();
	           		$(".product_temp").hide();
	           		if(select_chart == 1) $("#form_an2").hide();
	        		else $("#form_an1").hide();
	           	}
	
	           	if(product == 3){
	           		$(".label_product").show();
	           		$(".product_game").hide();
	           		$(".product_theme").show();
	           		$(".product_app").hide();
	           		$(".product_temp").hide();
	           		if(select_chart == 1) $("#form_an2").hide();
	        		else $("#form_an1").hide();
	           	}
	
	           	if(product == 4){
	           		$(".label_product").show();
	           		$(".product_game").hide();
	           		$(".product_theme").hide();
	           		$(".product_app").hide();
	           		$(".product_temp").show();
	           		if(select_chart == 1) $("#form_an2").hide();
	        		else $("#form_an1").hide();
	           	}	
	           	if(product == 5){
	           		$(".label_product").hide();
	           		$(".product_game").hide();
	           		$(".product_theme").hide();
	           		$(".product_app").hide();
	           		$(".product_temp").hide();
	           		if(select_chart == 1) $("#form_an2").hide();
	        		else $("#form_an1").hide();
	           	}
	         
	        var product_line_chanel = $("#typeproduct_chanel").val();   	
	        if(product_line_chanel == 1){
        		$(".label_product").show();
        		$(".product_game").show();
	        }
	        if(product_line_chanel == 2){
        		$(".label_product").show();
        		$(".product_app").show();
	        }
	        if(product_line_chanel == 3){
        		$(".label_product").show();
        		$(".product_theme").show();
	        }
	        if(product_line_chanel == 4){
        		$(".label_product").show();
        		$(".product_temp").show();
	        }
           	var product_line = $("#typeproduct").val();
            if(product_line == 1){
        		$(".label_product").show();
        		$(".product_game").show();
        		$(".product_theme").hide();
        		$(".product_app").hide();
        		$(".product_temp").hide();
        		if(select_chart == 1) $("#form_an2").hide();
     		else $("#form_an1").hide();
        	}
        	
        	if(product_line == 2){
        		$(".label_product").show();
        		$(".product_game").hide();
        		$(".product_theme").hide();
        		$(".product_app").show();
        		$(".product_temp").hide();
        		if(select_chart == 1) $("#form_an2").hide();
     		else $("#form_an1").hide();
        	}

        	if(product_line == 3){
        		$(".label_product").show();
        		$(".product_game").hide();
        		$(".product_theme").show();
        		$(".product_app").hide();
        		$(".product_temp").hide();
        		if(select_chart == 1) $("#form_an2").hide();
     		else $("#form_an1").hide();
        	}

        	if(product_line == 4){
        		$(".label_product").show();
        		$(".product_game").hide();
        		$(".product_theme").hide();
        		$(".product_app").hide();
        		$(".product_temp").show();
        		if(select_chart == 1) $("#form_an2").hide();
     		else $("#form_an1").hide();
        	}	
        	if(product_line == 5){
        		$(".label_product").hide();
        		$(".product_game").hide();
        		$(".product_theme").hide();
        		$(".product_app").hide();
        		$(".product_temp").hide();
        		if(select_chart == 1) $("#form_an2").hide();
     		else $("#form_an1").hide();
        	}
 // xu ly de ve bieu do              
            var type_chart = $("#test").val();
    	    if(type_chart ==  1){
    	        $("#container_line").remove();
    	        $("#container_line_chanel").remove();
				var name_site = $("#temp_name").val();   //a
				var value_download = $("#temp_value").val();  //b
				var name_site_array = name_site.split("/");   // mang
				var n;
				var temp = new Array();
			    var value_download_array = value_download.split(" ");  // giatri
			    n = value_download_array.length;
			    for(var i = 0; i < n-1 ; i++)
			    {
                      temp[i] = parseFloat(value_download_array[i]);
			    }
			    var data_chart = new Array();  // tam
			    for(var i = 0; i < n-1 ; i++)
			    {
                    data_chart[i] = {
	                 		   name: name_site_array[i],
	                		   data: temp[i]
	                		 }; 
			    }
					    chart = new Highcharts.Chart({
							chart: {
								renderTo: 'container',
								defaultSeriesType: 'bar'
							},
							title: {
								text: 'BIỂU ĐỒ SO SÁNH LƯỢT DOWNLOAD TRÊN CÁC KÊNH'
							},
							subtitle: {
								text: 'Source: Sunnet'
							},
							xAxis: {
								categories: [' ', ' '],
								title: {
									text: null
								}
							},
							yAxis: {
								min: 0,
								title: {
									text: 'Lượt download',
									align: 'high'
								}
							},
							tooltip: {
								formatter: function() {
									return ''+
										 this.series.name +': '+ numberFormat(this.y) + ' Lượt download' ;
								}
							},
							plotOptions: {
								bar: {
									dataLabels: {
										enabled: true
									}
								}
							},
							legend: {
								layout: 'vertical',
								align: 'right',
								verticalAlign: 'top',
								x: -100,
								y: 100,
								floating: true,
								borderWidth: 1,
								backgroundColor: '#FFFFFF',
								shadow: true
							},
							credits: {
								enabled: false
							},
							series: data_chart
						}); 
				
    	   }
    	       
		if(type_chart == 2){ 
				chart_chanel = $("#chart_chanel").val();
				$("#container_bar").remove();
				if(chart_chanel == 1) $("#container_line").remove();
				else $("#container_line_chanel").remove();
			    if((date_time == 3) || (date_time == 2)){
					var n = $("#so_phan_tu").val();	
					var date_string = $("#date_string").val();
					date_string = date_string.split("/");
					
				    var name_site = $("#temp_name1").val();	
				    var araay_temp = new Array();	
				    var temp_string;	
				    var value_download_array =  new Array();  
				    var length =  new Array();	
				    for(var k = 0 ; k < n ; k++)
				    {
				    	temp_string = "temp_value";
					    var value_download_site = temp_string.concat(k); // alert(ma_id);
					    araay_temp[k] = $("#" + value_download_site).val();// alert(mang_1[k]);
					    value_download_array[k] =  araay_temp[k].split(" "); // alert(mang_gia_tri[k]);
					    length[k] =  value_download_array[k].length;
				    }
					var name_site_array = name_site.split("/");
					var data_download = new Array();	
					
				    for(var i = 0; i < n ; i++)
				    {
				    	data_download[i] = new Array();
					      for(var j=0; j < value_download_array[i].length - 1; j++)
					      {
					    	  data_download[i][j] = (parseFloat(value_download_array[i][j])); //alert(mang_tam1[j]);
					      }
				    }
				   
				    var data_chart = new Array();	
				    for(var t = 0; t < n ; t++)
				    {  
	                    data_chart[t] = { 
		                 		   name: name_site_array[t],
		                		   data: data_download[t]
		                		 }; 
				    }
				   
				    chart = new Highcharts.Chart({
								chart: {
									renderTo: 'container',
									defaultSeriesType: 'line',
									marginRight: 10,
									marginBottom: 25
								},
								title: {
									text: 'BIỂU ĐỒ TĂNG TRƯỞNG SẢN PHẨM',
									x: -20 //center
								},
								subtitle: {
									text: 'Source: Sunnet',
									x: -20
								},
								xAxis: {
									categories: date_string,
									labels : {rotation: -45, align: 'right',y:-30},
									title: {
												text: 'Ngày',
												align: 'high',
												margin: -75
											}
									
								},
								yAxis: {
									title: {
										text: 'Lượt download'
									},
									plotLines: [{
										value: 0,
										width: 1,
										color: '#808080'
									}]
								},
								tooltip: {
									formatter: function() {
							                return '<b>'+ this.series.name +'</b><br/>'+ 'Ngày ' +
											this.x +': '+ numberFormat(this.y) + ' Lượt download' ;
									}
								},
								legend: {
									layout: 'vertical',
									align: 'right',
									verticalAlign: 'top',
									x: -50,
									y: 50,
									borderWidth: 0
								},
								series: data_chart
								
							});
			}
			else if(date_time == 1){
				var n = $("#so_phan_tu").val();	
				var date_string = $("#date_string").val();
				date_string = date_string.split("/");
				
			    var name_site = $("#temp_name1").val();	
			    var araay_temp = new Array();	
			    var temp_string;	
			    var value_download_array =  new Array();  
			    var length =  new Array();	
			    for(var k = 0 ; k < n ; k++)
			    {
			    	temp_string = "temp_value";
				    var value_download_site = temp_string.concat(k); // alert(ma_id);
				    araay_temp[k] = $("#" + value_download_site).val();// alert(mang_1[k]);
				    value_download_array[k] =  araay_temp[k].split(" "); // alert(mang_gia_tri[k]);
				    length[k] =  value_download_array[k].length;
			    }
				var name_site_array = name_site.split("/");
				var data_download = new Array();	
				
			    for(var i = 0; i < n ; i++)
			    {
			    	data_download[i] = new Array();
				      for(var j=0; j < value_download_array[i].length - 1; j++)
				      {
				    	  data_download[i][j] = (parseFloat(value_download_array[i][j])); //alert(mang_tam1[j]);
				      }
			    }
			   
			    var data_chart = new Array();	
			    for(var t = 0; t < n ; t++)
			    {  
                    data_chart[t] = { 
	                 		   name: name_site_array[t],
	                		   data: data_download[t]
	                		 }; 
			    }
			    chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container',
						defaultSeriesType: 'line',
						marginRight: 10,
						marginBottom: 25
					},
					title: {
						text: 'BIỂU ĐỒ TĂNG TRƯỞNG SẢN PHẨM',
						x: -20 //center
					},
					subtitle: {
						text: 'Source: Sunnet',
						x: -20
					},
					xAxis: {
						categories: date_string,
						labels : {rotation: -45, align: 'right',y:-50},
						
						title: {
									text: 'Tháng',
									align: 'high',
									margin: -75
								}
						
					},
					yAxis: {
						title: {
							text: 'Lượt download'
						},
						plotLines: [{
							value: 0,
							width: 1,
							color: '#808080'
						}]
					},
					tooltip: {
						formatter: function() {
				                return '<b>'+ this.series.name +'</b><br/>'+ 'Tháng ' +
								this.x +': '+ numberFormat(this.y) + ' Lượt download' ;
						}
					},
					legend: {
						layout: 'vertical',
						align: 'right',
						verticalAlign: 'top',
						x: -50,
						y: 50,
						borderWidth: 0
					},
					series: data_chart
					
				});
				}
		}	
		});
